<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';
session_start();
class Relation extends REST_Controller {
	public function __construct() {
		parent::__construct();
		$this->load->model('User_model');
		$this->load->library('session');
	
	}
	/**
	 *
	 */
	public function get_app_friends_get() {
		if ((!$this->get('openid')) || (!$this->get('openkey')) ) {
			$this->response(array(
					'ret' => 1,
					'msg'=>'is not login',
			), 1);
		}
		else {
			$openid =  $this->get('openid');
			$openkey = $this->get('openkey');
		}
		//if(($this->session->userdata('id') == $openid)&&($this->User_model->check_session_id($openid,$openkey))){
		if(!$this->User_model->check_session_id($openid,$openkey)) {
			$this->response(array(
					'ret' => 1,
					'msg'=>'is not login',
			), 1);
		}else{
			$user_id = $openid;
		}
		//$user_id=$this->session->userdata('id');
		//$friends_list = array();
		try{
		$friends_list = $this->User_model->get_app_friends_facebook($user_id);
		}
		catch(Exception $e){
			var_dump($e->getMessage());die();
		}
	
		if ($friends_list == null) {
			$friends_list = array();
		}
		//var_dump($friends_list); die();

		$this->response(array(
				'ret' => 0,
				'is_lost'=>'0',
				'items' => $friends_list
		), 1);



	}
	public function getFriendIds_get() {
		$this->load->model('Facebook_model');
		$friend_list = $this->Facebook_model->getFriendIds();
		var_dump($friend_list);
	}

}
// "ret":0,
// "is_lost":0,
// "items":[
// {"openid":"9CE729C9927532BABBB57F6AB000925B"},
// {"openid":"08B8273CACFBE0D9F57CAB4E7D8BDBF0"}